package com.example.project_dish.Dishes;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.project_dish.Dishes.Dishes;
import com.example.project_dish.Dishes.DishesAdapter;
import com.example.project_dish.Dishes.DishesDetail;
import com.example.project_dish.Dishes.RightFragment;
import com.example.project_dish.R;

import java.util.ArrayList;
import java.util.Arrays;

public class LeftFragment extends Fragment {
    private ArrayList<Dishes> dishesList = new ArrayList<>(); //左边菜品列表
    /**
     * 绑定java类和碎片布局文件  fragment_left.xml
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //  根据布局文件去创建碎片的视频界面
        View view = inflater.inflate(R.layout.fragment_left,container,false);
        initDishes();
        DishesAdapter dishesAdapter = new DishesAdapter(getContext(), R.layout.dishes_item, dishesList);
        ListView listView = (ListView) view.findViewById(R.id.lv1);
        listView.setAdapter(dishesAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                // 把水果数据传给右边布局，去展示出来
                // 1. 拿到水果数据
                Dishes dishes = dishesList.get(i);
                //2. 拿到右边碎片视图对象
                RightFragment rightFragment = (RightFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.right_frag);
                // 调用右边碎片的方法，刷新数据
                rightFragment.refresh(dishes);
            }
        });
        return view;
    }

    private void initDishes(){
        Dishes lu = new Dishes("鲁菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.lu, 100, "木须肉"), new DishesDetail(R.drawable.lu1, 110, "锅塌豆腐"), new DishesDetail(R.drawable.lu2, 77, "四喜丸子"), new DishesDetail(R.drawable.lu3, 79, "糖醋里脊"), new DishesDetail(R.drawable.lu4, 105, "油焖大虾")}));
        Dishes chuan = new Dishes("川菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.chuan1, 100, "宫保鸡丁"), new DishesDetail(R.drawable.chuan2, 110, "水煮豆皮肉片"), new DishesDetail(R.drawable.chuan3, 77, "双椒回锅肉"), new DishesDetail(R.drawable.chuan5, 79, "水煮鱼片"), new DishesDetail(R.drawable.chuan6, 105, "四川哨子面")}));
        Dishes yue = new Dishes("粤菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.yue1, 100, "豉油皇鸭肠"), new DishesDetail(R.drawable.yue2, 110, "广式叉烧肉"), new DishesDetail(R.drawable.yue3, 77, "广式腊味煲仔饭"), new DishesDetail(R.drawable.yue4, 79, "碌鸭"), new DishesDetail(R.drawable.yue5, 105, "猪脚姜")}));
        Dishes su = new Dishes("苏菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.su1, 100, "赣榆煎饼卷三丝"), new DishesDetail(R.drawable.su2, 110, "红烧划水"), new DishesDetail(R.drawable.su3, 77, "蜜三刀"), new DishesDetail(R.drawable.su4, 79, "松鼠鱼"), new DishesDetail(R.drawable.su5, 105, "无锡排骨")}));
        Dishes min = new Dishes("闽菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.ming, 100, "炒笋粿 "), new DishesDetail(R.drawable.ming2, 110, "河蚬汤"), new DishesDetail(R.drawable.ming3, 77, "酒糟鸡"), new DishesDetail(R.drawable.ming4, 79, "闽南蚝仔煎"), new DishesDetail(R.drawable.ming5, 105, "青椒酿肉")}));
        Dishes zhe = new Dishes("浙菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.zhe1, 100, "豆沙八宝饭"), new DishesDetail(R.drawable.zhe2, 110, "鸡翅炖年糕"), new DishesDetail(R.drawable.zhe3, 77, "鲮鱼饼虾仁汤年糕"), new DishesDetail(R.drawable.zhe4, 79, "温州松糕"), new DishesDetail(R.drawable.zhe5, 105, "炸响铃")}));
        Dishes xiang = new Dishes("湘菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.xiang1, 100, "剁椒鱼头"), new DishesDetail(R.drawable.xiang2, 110, "干捞粉丝"), new DishesDetail(R.drawable.xiang3, 77, "湖南坛子伏鱼"), new DishesDetail(R.drawable.xiang4, 79, "擂辣椒皮蛋"), new DishesDetail(R.drawable.xiang5, 105, "麻婆豆腐")}));
        Dishes hui = new Dishes("徽菜", Arrays.asList(new DishesDetail[]{new DishesDetail(R.drawable.wei, 100, "家传红烧肉"), new DishesDetail(R.drawable.wei2, 110, "梅干菜烧饼"), new DishesDetail(R.drawable.wei3, 77, "香肠肉松粢饭"), new DishesDetail(R.drawable.wei4, 79, "腌笃鲜"), new DishesDetail(R.drawable.wei5, 105, "鱼咬羊")}));
            dishesList.add(lu);
            dishesList.add(chuan);
            dishesList.add(yue);
            dishesList.add(su);
            dishesList.add(min);
            dishesList.add(zhe);
            dishesList.add(xiang);
            dishesList.add(hui);
    }
}
